package com.kaki.mdb;

import org.springframework.core.io.ClassPathResource;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

/**
 * @author Kaki Nakajima
 * @description DB Show 提示窗口
 * @date 2024-09-17 10:11
 */
public class AlertFrame implements ActionListener {

    // 提示
    public static void alert(String resultStr) throws IOException {
        JFrame window1 = new JFrame("结果");

        // 初始化容器
        Container container = window1.getContentPane();
        container.setBackground(new Color(204,238,200));

        // 本地图片
        ImageIcon imageIcon = new ImageIcon(new ClassPathResource("/photos/main.png").getURL());
        window1.setIconImage(imageIcon.getImage());

        window1.setBounds(600,230,700,520);
        window1.setVisible(true);
        window1.setLayout((LayoutManager) null);

        // 标题组
        JLabel label_username = new JLabel("操作结果（返回请点击x）");
        label_username.setFont(new Font("微软雅黑",Font.LAYOUT_NO_LIMIT_CONTEXT,20));
        JButton cfam = new JButton("请点击x");
        cfam.setBackground(Color.magenta);

        // 盒子组
        Box userInputBox = Box.createVerticalBox();
        Box buttonBox = Box.createHorizontalBox();
        Box usernameBox = Box.createHorizontalBox();
        Box passwordBox = Box.createHorizontalBox();

        usernameBox.add(label_username);
        usernameBox.add(Box.createHorizontalStrut(10));

        // 文本域
        JTextArea textArea = new JTextArea();
        textArea.setText(resultStr);
        textArea.setFont(new Font("微软雅黑",Font.LAYOUT_NO_LIMIT_CONTEXT,20));

        // 文本盒子域
        userInputBox.add(usernameBox);
        userInputBox.add(Box.createHorizontalStrut(102));
        userInputBox.add(new JScrollPane(textArea){
            @Override
            public Dimension getPreferredSize(){
                return new Dimension(1330,600);
            }
        });
        userInputBox.add(passwordBox);

        // 按钮组
        buttonBox.add(Box.createHorizontalStrut(10));
        buttonBox.add(cfam);

        //页面位置
        userInputBox.setBounds(34,20,600,440);
        buttonBox.setBounds(265,200,400,100);

        // 总容器
        window1.add(userInputBox);
        window1.setDefaultCloseOperation(2);
        window1.validate();
    }

    @Override
    public void actionPerformed(ActionEvent e) {

    }
}
